package com.xkstream.client.presenter;

import com.xkstream.client.api.UserApi;
import com.xkstream.client.api.UserService;
import com.xkstream.client.base.BaseData;
import com.xkstream.client.base.BasePresenterImpl;
import com.xkstream.client.entity.User;
import com.xkstream.client.rx.RxHelper;
import com.xkstream.client.rx.RxObserver;

import java.util.Map;

/**
 * Created by xiaoyi on 2017-8-28.
 */

public class RegisterPresenter extends BasePresenterImpl implements RegisterContract.Presenter {
    private RegisterContract.View view;
    private UserService userService;
    public RegisterPresenter(RegisterContract.View view) {
        this.view = view;
        userService = UserApi.getInstance().service;
    }

    @Override
    public void anchorRegister(Map<String, String> params) {
        view.showLoading();
        userService.anchorRegister(params)
                .compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData>(this) {
                    @Override
                    protected void onSuccess(BaseData baseData) {
                        view.hideLoading();
                        view.showRegisterResult(baseData);
                    }

                    @Override
                    protected void onFail(String message) {
                        view.hideLoading();
                    }
                });
    }



}
